home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / langs / gfaxpert.lzh / GFAXPERT.LIB / ARRAYWRD.LST < prev    next >
Encoding:
File List  |  1986-10-19  |  5.7 KB  |  271 lines

  1. ' ********************
  2. ' *** ARRAYWRD.LST ***
  3. ' ********************
  4. ' *** important : element with index 0 is ignored !!
  5. '
  6. DEFWRD "a-z"
  7. '
  8. > PROCEDURE max.array(VAR proc(),high)
  9.   ' *** return highest value of array proc()
  10.   LOCAL last,n
  11.   last=DIM?(proc())-1
  12.   high=proc(1)
  13.   FOR n=2 TO last
  14.     high=MAX(high,proc(n))
  15.   NEXT n
  16. RETURN
  17. ' **********
  18. '
  19. > PROCEDURE min.array(VAR proc(),low)
  20.   ' *** return lowest value of array proc()
  21.   LOCAL last,n
  22.   last=DIM?(proc())-1
  23.   low=proc(1)
  24.   FOR n=2 TO last
  25.     low=MIN(low,proc(n))
  26.   NEXT n
  27. RETURN
  28. ' **********
  29. '
  30. > PROCEDURE max.elem.array(VAR proc(),index,high)
  31.   ' *** return index and value of highest element of array proc()
  32.   LOCAL last,n
  33.   last=DIM?(proc())-1
  34.   high=proc(1)
  35.   FOR n=2 TO last
  36.     high=MAX(high,proc(n))
  37.   NEXT n
  38.   index=1
  39.   WHILE proc(index)<high
  40.     INC index
  41.   WEND
  42. RETURN
  43. ' **********
  44. '
  45. > PROCEDURE min.elem.array(VAR proc(),index,low)
  46.   ' *** return index and value of lowest element of array proc()
  47.   LOCAL last,n
  48.   last=DIM?(proc())-1
  49.   low=proc(1)
  50.   FOR n=2 TO last
  51.     low=MIN(low,proc(n))
  52.   NEXT n
  53.   index=1
  54.   WHILE proc(index)>low
  55.     INC index
  56.   WEND
  57. RETURN
  58. ' **********
  59. '
  60. > PROCEDURE max.min.array(VAR proc(),high,low)
  61.   ' *** return highest and lowest value of array proc()
  62.   LOCAL last,n
  63.   last=DIM?(proc())-1
  64.   high=proc(1)
  65.   low=proc(1)
  66.   FOR n=2 TO last
  67.     high=MAX(high,proc(n))
  68.     low=MIN(low,proc(n))
  69.   NEXT n
  70. RETURN
  71. ' **********
  72. '
  73. > PROCEDURE som.array(VAR proc(),som%)
  74.   ' *** return sum of numbers in array proc()
  75.   LOCAL last,n
  76.   last=DIM?(proc())-1
  77.   som%=0
  78.   FOR n=1 TO last
  79.     ADD som%,proc(n)
  80.   NEXT n
  81. RETURN
  82. ' **********
  83. '
  84. > PROCEDURE middle.array(VAR proc(),middle)
  85.   ' *** return middle value of array proc()
  86.   LOCAL last,med,l,u,i,j,x
  87.   last=DIM?(proc())-1
  88.   DIM hulp.proc(last)
  89.   FOR i=1 TO last
  90.     hulp.proc(i)=proc(i)
  91.   NEXT i
  92.   med=(last+1)/2
  93.   l=1
  94.   u=last
  95.   WHILE l<u
  96.     i=1
  97.     j=u
  98.     x=hulp.proc(med)
  99.     WHILE i<=med AND j>=med
  100.       WHILE hulp.proc(i)<x
  101.         INC i
  102.       WEND
  103.       WHILE hulp.proc(j)>x
  104.         DEC j
  105.       WEND
  106.       SWAP hulp.proc(i),hulp.proc(j)
  107.       INC i
  108.       DEC j
  109.     WEND
  110.     IF j<med
  111.       l=i
  112.     ENDIF
  113.     IF i>med
  114.       u=j
  115.     ENDIF
  116.   WEND
  117.   mediaan=hulp.proc(med)
  118.   ERASE hulp.proc()
  119. RETURN
  120. ' **********
  121. '
  122. > PROCEDURE average.array(zero!,VAR proc(),average#,deviation#)
  123.   ' *** return average and standard deviation of array proc()
  124.   ' *** zero!=TRUE : use value 0 ; zero!=FALSE : ignore value 0
  125.   LOCAL n,sum%,sum2%,i
  126.   CLR sum%,sum2%,i
  127.   IF zero!
  128.     GOSUB zero.average
  129.   ELSE
  130.     GOSUB no.zero.average
  131.   ENDIF
  132. RETURN
  133. ' ***
  134. > PROCEDURE no.zero.average
  135.   ' *** ignore 0 in computation
  136.   FOR n=1 TO DIM?(proc())-1
  137.     IF proc(n)<>0
  138.       ADD sum%,proc(n)
  139.       ADD sum2%,proc(n)*proc(n)
  140.       INC i
  141.     ENDIF
  142.   NEXT n
  143.   average#=sum%/i
  144.   deviation#=SQR((sum2%-sum%*sum%/i)/(i*(i-1)))
  145. RETURN
  146. ' ***
  147. > PROCEDURE zero.average
  148.   ' *** use 0 in computation
  149.   FOR n=1 TO DIM?(proc())-1
  150.     ADD sum%,proc(n)
  151.     ADD sum2%,proc(n)*proc(n)
  152.     INC i
  153.   NEXT n
  154.   average#=sum%/i
  155.   deviation#=SQR((sum2%-sum%*sum%/i)/(i*(i-1)))
  156. RETURN
  157. ' **********
  158. '
  159. > PROCEDURE freq.array(elem,VAR proc(),freq)
  160.   ' *** return frequency of value elem in array proc()
  161.   LOCAL last,n
  162.   last=DIM?(proc())-1
  163.   freq=0
  164.   FOR n=1 TO last
  165.     IF proc(n)=elem
  166.       INC freq
  167.     ENDIF
  168.   NEXT n
  169. RETURN
  170. ' **********
  171. '
  172. > PROCEDURE freq.limit.array(limit,VAR proc(),freq)
  173.   ' *** return frequency of all numbers >= limit in array proc()
  174.   LOCAL last,n
  175.   last=DIM?(proc())-1
  176.   freq=0
  177.   FOR n=1 TO last
  178.     IF proc(n)>=limit
  179.       INC freq
  180.     ENDIF
  181.   NEXT n
  182. RETURN
  183. ' **********
  184. '
  185. > PROCEDURE all.freq.array(VAR proc(),freq())
  186.   ' *** return frequency of all integers in array proc()
  187.   ' *** only integers >= 0 allowed in array proc()
  188.   ' *** frequency-array must already exist !
  189.   ' *** integers must vary from 0 to last index of frequency-array !
  190.   LOCAL last,max,i,j
  191.   last=DIM?(proc())-1
  192.   max=DIM?(freq())-1
  193.   FOR i=0 TO max
  194.     FOR j=1 TO last
  195.       IF proc(j)=i
  196.         INC freq(i)
  197.       ENDIF
  198.     NEXT j
  199.   NEXT i
  200. RETURN
  201. ' **********
  202. '
  203. > PROCEDURE step.freq.array(step,VAR proc(),freq())
  204.   ' *** return frequency of all integers in array proc()
  205.   ' *** array proc() contains multiples of step only !
  206.   ' *** example with step=5 : 0,5,15,20,25,....95,100
  207.   ' *** remember, freq(3) contains frequency of value 3*step !
  208.   LOCAL last,max,i,j
  209.   last=DIM?(proc())-1
  210.   max=(DIM?(freq())-1)*step
  211.   FOR i=0 TO max STEP step
  212.     FOR j=1 TO last
  213.       IF proc(j)=i
  214.         INC freq(DIV(i,step))
  215.       ENDIF
  216.     NEXT j
  217.   NEXT i
  218. RETURN
  219. ' **********
  220. '
  221. > PROCEDURE shuffle.array(VAR proc())
  222.   ' *** shuffle integers in array proc()
  223.   LOCAL n,j
  224.   FOR n=DIM?(proc())-1 DOWNTO 2
  225.     j=RAND(n)+1                     ! random number (1 - n)
  226.     SWAP proc(j),proc(n)
  227.   NEXT n
  228. RETURN
  229. ' **********
  230. '
  231. > PROCEDURE compress.array(VAR proc())
  232.   ' *** remove duplicates from sorted array proc()
  233.   ' *** dimension of array will be changed after deletions !
  234.   LOCAL last,i,j
  235.   last=DIM?(proc())-1
  236.   i=2
  237.   WHILE proc(i-1)<>proc(i) AND i<last
  238.     INC i
  239.   WEND
  240.   IF proc(i-1)<>proc(i)
  241.     INC i
  242.   ENDIF
  243.   j=i-1
  244.   WHILE i<last
  245.     INC i
  246.     IF proc(i-1)<>proc(i)
  247.       INC j
  248.       proc(j)=proc(i)
  249.     ENDIF
  250.   WEND
  251.   DIM new.proc(j)
  252.   FOR i=1 TO j
  253.     new.proc(i)=proc(i)
  254.   NEXT i
  255.   SWAP proc(),new.proc()
  256.   ERASE new.proc()
  257. RETURN
  258. ' **********
  259. '
  260. > PROCEDURE reverse.array(VAR proc())
  261.   ' *** reverse array proc()
  262.   LOCAL last,half,n
  263.   last=DIM?(proc())-1
  264.   half=last/2
  265.   FOR n=1 TO half
  266.     SWAP proc(n),proc(last+1-n)
  267.   NEXT n
  268. RETURN
  269. ' **********
  270. '
  271.